import { useCallback , useState } from 'react'
//https://blog.csdn.net/roamingcode/article/details/104111165
const useSetState = <T extends Record<string,any>>(
  initialState:T = {} as T,
):[T,(patch:Partial<T> |((prevState:T)=>Partial<T>))=>void]=>{
  const [state ,set] = useState(initialState)
  const setState = useCallback(
    (patch)=>{
      set((prevState) => Object.assign({},prevState,patch instanceof Function ? patch(prevState) : patch))
    },
    [set]
  )  

  return [state , setState]
}

export default useSetState